
#include "ws2812b.h"

#include "esp_log.h"
#include "driver/gpio.h"
#include "neopixel.h"

#include "sdkconfig.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"


void test_1(uint32_t iterations)
{
   tNeopixelContext neopixel = neopixel_Init(LED_COUNT, LED_PIN);
   tNeopixel pixel[] =
   {
       { 0, NP_RGB(0, 0,  50) }, 
       { 1, NP_RGB(0,  50, 0) }, /* green */
       { 2, NP_RGB(0,  0, 50) }, /* blue */
       { 3, NP_RGB(50,  50,  0) }, 
       { 4, NP_RGB(0, 50,  50) }, 
       { 5, NP_RGB(50, 0, 50) }, 
       { 6, NP_RGB(50,  50, 50) },
       { 7, NP_RGB(50,  0,  0) }, 

   };

   for(int iter = 0; iter < iterations; ++iter)
   {
      for(int i = 0; i < ARRAY_SIZE(pixel); ++i)
      {
      
         neopixel_SetPixel(neopixel, pixel, 8);
         vTaskDelay(pdMS_TO_TICKS(20));
         
      }
   }
   neopixel_Deinit(neopixel);
 
}


void test_2(uint32_t iterations)
{
   tNeopixelContext neopixel = neopixel_Init(LED_COUNT, LED_PIN);
   uint32_t refreshRate, taskDelay;

   refreshRate = neopixel_GetRefreshRate(neopixel);
   taskDelay = MAX(1, pdMS_TO_TICKS(1000UL / refreshRate));

   for(uint32_t i = 0; i < iterations * LED_COUNT; ++i)
   {
      tNeopixel pixel[] =
      {
          { (i)   % LED_COUNT, NP_RGB(0, 0,  0) },
          { (i+5) % LED_COUNT, NP_RGB(0, 50, 0) }, /* green */
      };
      //neopixel_SetPixel(neopixel, pixel, ARRAY_SIZE(pixel));
      neopixel_SetPixel(neopixel, pixel, 2);
      
      vTaskDelay(taskDelay);
   }

   neopixel_Deinit(neopixel);
  
}